package com.cl.short_video_java.web.sys_setting;

import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.cl.short_video_java.annotation.IsRole;
import com.cl.short_video_java.annotation.Login;
import com.cl.short_video_java.common.Const;
import com.cl.short_video_java.common.Result;
import com.cl.short_video_java.menum.MessageType;
import com.cl.short_video_java.pojo.SysNotice;
import com.cl.short_video_java.service.SysNoticeService;
import com.cl.short_video_java.vo.sys.Notice;
import com.cl.short_video_java.vo.sys.NoticeSearch;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.*;

import javax.servlet.http.HttpServletRequest;
import java.util.List;

/**
 * @Author 付
 * @Date 2024-11-06 17:01
 * @Version 1.0
 * @description 通知公告接口类
 * @since 1.0
 */
@RestController
@RequestMapping("/notice")
public class NoticeController {

	private SysNoticeService sysNoticeService;

	public NoticeController(SysNoticeService sysNoticeService) {
		this.sysNoticeService = sysNoticeService;
	}

	/**
	 * 获取通知列表
	 *
	 * @param noticeSearch
	 * @return
	 */
	@PostMapping("/list")
	@Login(issuer = Const.GRADE_ADMIN)
	public Result list(@RequestBody @Validated NoticeSearch noticeSearch) {
		Page<SysNotice> list = sysNoticeService.page(noticeSearch);
		return Result.success(list);
	}

	@PostMapping("/insert")
	@Login(issuer = Const.GRADE_ADMIN)
	@IsRole(menuId = 31)
	public Result insert(@Validated @RequestBody Notice notice, HttpServletRequest request) {
		sysNoticeService.insert(notice, request);
		return Result.success(MessageType.OPER_SUCCESS);
	}

	@PostMapping("/del")
	@Login(issuer = Const.GRADE_ADMIN)
	@IsRole(menuId = 32)
	public Result del(@RequestBody List<Integer> ids) {
		sysNoticeService.del(ids);
		return Result.success(MessageType.DELETE_SUCCESS);
	}

}
